package test

/**
 * @author: Yardena
 * @date: Oct 15, 2009 4:45:09 PM
 */
import scala.reflect.Manifest
import htmap.HTMap;

object Test5 {

  trait Column[T<:Table] { def name:String }
  trait Table
  trait Boo extends Table
  class Foo extends Column[Boo] { val name = "foo" }
  class Bar extends Column[Boo] { val name = "bar" }

  def record[A,B](x:(A,B)):Duo[A,B] = Duo(x._1,x._2)
  def record[A,B,C](x:(A,B,C)):Trio[A,B,C] = Trio(x._1,x._2,x._3)

  def main(args : Array[String]) {
    val x:HTMap[Int with String] = record(3,"foo",false)
    println(x./[Int] + 5);
    println(x./[String].indexOf("f"))
    type Thing = {
      type Amount = Int
      type Name = String
    }
    println(x./[Thing#Amount] + 5);
    println(x./[Thing#Name].indexOf("f"))
    val boo = Duo(new Foo, new Bar)
    println(boo./[Foo].name);
    println(boo./[Bar].name)
    ;
  }

  trait Record extends Product
  class Duo[A,B](a:A,b:B) extends Tuple2(a,b) with Record {
    def *[C](c:C) = Trio(a,b,c)
  }
  object Duo {
    def apply[A,B](a:A,b:B) = new Duo(a,b)
    implicit def flat[A,B](p:Duo[A,B])
                          (implicit ma:Manifest[A], mb:Manifest[B])
                          :HTMap[A with B] = { HTMap().+(p._1)(ma).+(p._2)(mb) }
  }

  class Trio[A,B,C](a:A,b:B,c:C) extends Duo(a,b) with Product3[A,B,C] {
    override def _3 = c
  }
  object Trio {
    def apply[A,B,C](a:A,b:B,c:C) = new Trio(a,b,c)
    implicit def flat[A,B,C](p:Trio[A,B,C])
                          (implicit ma:Manifest[A],mb:Manifest[B],mc:Manifest[C] )
                          :HTMap[A with B with C] = { HTMap().+(p._1)(ma).+(p._2)(mb).+(p._3)(mc) }
  }
}